import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('First Web'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}

//body内容组件
class HomeContent extends StatelessWidget {
  //真实场景是从服务器获取数据然后生成list widget
  List<Widget> _getWidgetData() {
    List<Widget> list = [];

    for (var i = 0; i < 3; i++) {
      list.add(ListTile(
        trailing: Icon(Icons.ac_unit_outlined),
        leading: Icon(
          Icons.new_releases,
          color: Colors.amber,
          size: 30,
        ),
        title: Text(
          "我是$i",
          style: TextStyle(fontSize: 26),
        ),
        subtitle: Text(
          "我是副标题$i",
          style: TextStyle(fontSize: 18),
        ),
      ));
    }

    list.add(ListTile(
      title: Text("远程图片"),
      subtitle: Text("我是副标题"),
      leading: Image.network(
          "https://pic3.zhimg.com/v2-d109b212df1b784ccc65ff905524134a_1440w.jpg?source=172ae18b"),
      trailing: Image.asset("images/independentmind.jpeg"),
    ));

    list.add(ListTile(
      title: Text("本地图片"),
      subtitle: Text("我是副标题"),
      leading: Image.asset("images/independentmind.jpeg"),
      trailing: Image.asset("images/independentmind.jpeg"),
    ));
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: EdgeInsets.all(10),
      //可以有多种组件Container, Image,ListTile等
      children: this._getWidgetData(),
    );
  }
}
